import service from '../utils/axios'
import type { ApiResponse } from '../utils/axios'
import type { UserData } from '../store/user'

// 验证码响应接口
interface CaptchaResponse {
  image: string // 验证码图片base64
  uuid: string // 验证码唯一标识
}

// 登录请求接口
interface LoginRequest {
  username: string
  password: string
  captcha: string
  uuid: string
}

// 注册请求接口
interface RegisterRequest {
  username: string
  password: string
  email?: string
  phone?: string
  captcha: string
  uuid: string
}

/**
 * 获取验证码
 */
export function getCaptcha(): Promise<ApiResponse<CaptchaResponse>> {
  return service({
    url: '/api/captcha',
    method: 'get'
  })
}

/**
 * 用户登录
 */
export function login(data: LoginRequest): Promise<ApiResponse<UserData>> {
  return service({
    url: '/api/auth/login',
    method: 'post',
    data
  })
}

/**
 * 用户注册
 */
export function register(data: RegisterRequest): Promise<ApiResponse<{ success: boolean }>> {
  return service({
    url: '/api/auth/register',
    method: 'post',
    data
  })
}

